package com.silp.labs.cacticlient;

public class TreeData {
	public int lenght = 0;
	public Host[] host= new Host[100];
	public String name = "";
	public TreeData()
	{
		//host = new Host[0];
	}
	public void AddHost(Host a)
	{
		host[lenght] = a;
		lenght +=1;
	}
	public Boolean CheckHostExist(String hostname)
	{
		
		for(int i =0; i<lenght; i ++)
		{
			if (host[i].hostname.trim() == hostname)
			{
				return true;
			}
		}
		return false;
	}
	public static int GetTreeIndex(TreeData[] arr, int n, String name)
	{
		for (int i = 0; i < n; i++) {
			TreeData treeData = arr[i];
			if (treeData.name.trim().equalsIgnoreCase(name.trim()) == true)
			{
				return i;
			}
			
		}
		return -1;
	}
	public int getHost(String hostname)
	{
		for (int i = 0; i < host.length; i++) {
			Host array_element = host[i];
			if (array_element.hostname.trim().equalsIgnoreCase(hostname.trim()) == true)
			{
				return i;
			}
		}
		return -1;
	}
	public static Boolean CheckTreeExist(TreeData[] tree,int lenght,String treename)
	{
		for (int i = 0; i < lenght; i++) {
			TreeData treeData = tree[i];
			if (treeData.name.trim().equalsIgnoreCase(treename.trim()) == true)
			{
				return true;
			}
			
		}
		return false;
	}
	public String[] getHostList()
	{
		String[] rr = new String[lenght];
		for (int i = 0; i <lenght; i++) {
			Host h = host[i];
			rr[i] = h.hostname;
		}
		return rr;
		
	}
	public static String[] getTreeListName(TreeData[] arr, int n)
	{
		String[] rr = new String[n];
		for (int i = 0; i < n; i++) {
			TreeData tr = arr[i];
			rr[i] = tr.name;
		}
		return rr;
	}
}
